<?php
/**
 * YICMS
 * ============================================================================
 * 版权所有 2014-2017 YICMS，并保留所有权利。
 * 网站地址: http://www.yicms.vip
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Created by PhpStorm.
 * Author: kenuo
 * Date: 2017/11/17
 * Time: 下午4:38
 */

namespace App\Services\Config;

use App\Handlers\role;
use App\Models\Config\Channels;
use App\Models\Config\Games;
use Auth;
use Route;
use Zhuzhichao\IpLocationZh\Ip;
use App\Repositories\Config\GamesRepository;
use Cache;

class GamesService
{

    protected $gamesRepository;

    /**
     * ActionLogsService constructor.
     * @param $actionLogsRepository
     */
    public function __construct(GamesRepository $gamesRepository)
    {
        $this->gamesRepository = $gamesRepository;
    }

    /**
     * 获取所有游戏
     */
    public function getPageGames($request)
    {
        $game = $this->gamesRepository->getPageGames($request);

        return $game;
    }

    /**
     * 获取所有游戏
     */
    public function getGames($condition = [])
    {
        $game = $this->gamesRepository->getWithGame($condition);

        return $game;
    }

    /**
     * 获取有权查看的 所有游戏
     */
    public function getGamesWithAuth()
    {
        $gamesAuth = role::getGamesAuth();
        $game = $this->gamesRepository->getGameWithAuth($gamesAuth);

        return $game;
    }

    public function ById($id)
    {
        return $this->gamesRepository->ById($id);
    }

    public function update($request, $id)
    {
        $datas = $request->all();

        $game = $this->gamesRepository->ById($id);
        $game->update($datas);

        return $game;
    }
}